﻿using System;
using System.Globalization;
using System.IO;
using System.ServiceModel.DomainServices.Client;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using DiagnosticCenter.Web;

namespace DiagnosticCenter.View
{
    public partial class viewOperatorHome : Page
    {
        public viewOperatorHome()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            gridProfile.DataContext = WebContext.Current.User;

            if (Application.Current.Host.Source != null)
            {
                var host = Application.Current.Host.Source.ToString();
                var AppPath = host.Substring(0, host.IndexOf("DiagnosticCenter.xap"));
                var AvatarFile = AppPath + "images/avatars/img_" + WebContext.Current.User.UserID + ".jpg";

                if (!File.Exists(AvatarFile))
                    AvatarFile = WebContext.Current.User.Sex == 1
                                     ? AppPath + "images/avatars/default_m.png"
                                     : AppPath + "images/avatars/default_w.png";

                imageUserPic.Source = new BitmapImage(new Uri(AvatarFile));
            }
        }

        private void DomainDataContext_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }
    }

}

//TODO: FIX: Не показывается аватар (исправить)
//TODO: NEW: доработать панельку "Список предметов"